<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/6
 * Time: 20:55
 */


require_once "../../php/config/database.php";
require_once "userDb.php";
$UserDb=new UserDb();
$user=$_POST['user'];
$password=$_POST['pass'];
$addtime=time();
$password=md5($password);
$datea=$UserDb->selectUser($user);

if($datea!=null) {
    session_start();
    $_SESSION['user']=$user;
    $data = $UserDb->selectPass($user, $password);
    try {
        $result = $data;
        if ($result) {
            $dat = array(
                'message' =>"登陆成功",
            );
            echo json_encode($dat);
        } else {
            $dat = array(

                'message' =>"登陆失败，密码错误",

            );
            echo json_encode($dat);

        }
    }
    catch (Exception $e) {

        // 回滚事务
        // $pdo->rollback();
        echo $e->getMessage();}

}
else
{

    $dat = array(

        'message' =>"登陆失败，你的账号不存在",

    );
    echo json_encode($dat);


}

